package com.wteam.dragon.system.util;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Getter;
import lombok.Setter;

import java.util.List;
import java.util.stream.Collectors;


/**
 * 将列表分页输出
 * @Author 陈晓辉
 * @Date 2020/5/25 9:57
 */
@Getter
@Setter
public class ListPageUtil{
    /**
     * 将列表分页，将结果存到Page中
     * @param page
     * @param list
     */
    public static <T> void dealPageList(Page<T> page, List<T> list) {
        long current = page.getCurrent();
        long size = page.getSize();
        long skip = (current - 1) * size;
        page.setTotal(list.size());
        page.setRecords(list.stream().skip(skip).limit(size).collect(Collectors.toList()));
    }
}
